package com.yourannet.android;

import com.supermap.jni.file_mgr.FileOperate;
import com.yourannet.utils.GpsUtils;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.location.LocationManager;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;

public class PositionRecord extends Activity implements OnClickListener{

	private Button btnStartPosition,btnEndPosition,btnExitPosition;
	private static LocationManager m_locationManager = null;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.position_record);
		cgt.jni.business.BXmlMgr config = cgt.jni.business.BXmlMgr.GetInstance();
		//全局变量赋值
		config.setRoot("sdcard/cgt_support_data/");
		String sdpath = FileOperate.getRootPath();
		Log.e("AppInit",sdpath+"");
		btnStartPosition=(Button)findViewById(R.id.btnStartLocation);
		btnStartPosition.setOnClickListener(this);
		btnEndPosition=(Button)findViewById(R.id.btnEndLocation);
		btnEndPosition.setOnClickListener(this);
		btnExitPosition=(Button)findViewById(R.id.btnExitLocation);
		btnExitPosition.setOnClickListener(this);
	}

	@Override
	protected void onDestroy() {
		// TODO Auto-generated method stub
		super.onDestroy();
	}

	@Override
	protected void onStart() {
		// TODO Auto-generated method stub
		super.onStart();
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch(v.getId()){
		case R.id.btnStartLocation:
			if(!GpsUtils.isGPSEnable(this)){
				GpsUtils.toggleGPS(this);
			}
			Toast.makeText(this, "开始记录位置信息!", Toast.LENGTH_LONG).show();
			Intent service = new Intent(); 
			service.putExtra("directory", "/sdcard/yourannet/position/");
			service.setAction("com.yourannet.android.PositionUpload");
			startService(service);
			break;
		case R.id.btnEndLocation:
			Toast.makeText(this, "停止记录位置信息!", Toast.LENGTH_LONG).show();
			Intent service2 = new Intent(); 
			service2.setAction("com.yourannet.android.PositionUpload");
			stopService(service2);
			break;
		case R.id.btnExitLocation:
			Intent service3 = new Intent(); 
			service3.setAction("com.yourannet.android.PositionUpload");
			stopService(service3);
			GpsUtils.toggleGPS(this);
			this.finish();
			break;
		}
	}

}
